<template>
  <div class="traceability-system">
    <!-- 顶部导航栏 -->
    <el-header class="header">
      <div class="header-left">
        <div class="company-name">爱吃兔食品加工有限公司</div>
        <el-menu mode="horizontal" :default-active="activeTopMenu" class="top-menu">
          <el-menu-item index="group">集团管理</el-menu-item>
          <el-menu-item index="enterprise" class="active">企业管理</el-menu-item>
          <el-menu-item index="platform">平台运营</el-menu-item>
          <el-menu-item index="system">系统设置</el-menu-item>
        </el-menu>
      </div>
      <div class="header-right">
        <span class="user-name">姓名:{{ pinia.login.userName }}</span>
        <el-button text>应用市场</el-button>
        <el-button text>客户端</el-button>
        <el-dropdown>
          <el-button text>
            <el-icon><MoreFilled /></el-icon>
          </el-button>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </el-header>

    <el-container class="main-container">
      <!-- 左侧菜单 -->
      <el-aside width="250px" class="sidebar">
        <div class="sidebar-header">
          <el-dropdown>
            <span class="sidebar-title">
              企业管理 
            </span>
          </el-dropdown>
        </div>
        
        <el-menu
          :default-active="activeSideMenu"
          class="sidebar-menu"
          @select="handleMenuSelect"
        >
          <el-menu-item index="traceability" class="active">
            <el-icon><Document /></el-icon>
            <span>溯源管理</span>
          </el-menu-item>
         
        </el-menu>
      </el-aside>

      <!-- 主内容区域 -->
      <el-main class="main-content">
        <keep-alive>
          <RouterView />
        </keep-alive>
      </el-main>
    </el-container>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { useCounterStore } from "@/stores/counter"
import router from '@/router'
import {
  Search,
  MoreFilled,
  ArrowDown,
  Document,
  Box,
  Check,
  House,
  Van,
  ShoppingCart
} from '@element-plus/icons-vue'

const pinia = useCounterStore()

// 响应式数据
const activeTopMenu = ref('enterprise')
const activeSideMenu = ref('traceability')
const searchKeyword = ref('')

// 方法
const handleMenuSelect = (index: string) => {
  activeSideMenu.value = index
  // 根据菜单选择跳转到对应页面
  switch (index) {
    case 'traceability':
      router.push('/listtrace')
      break

  }
}

const logout = () => {
  pinia.login.loginName = ""
  pinia.login.roleName = ""
  pinia.login.token = ""
  pinia.login.userId = null
  pinia.login.userName = ""
  router.push('/')
}
</script>

<style>
.el-header,.el-aside,.el-main{
  border: 1px solid #000000;
}
.el-aside,.el-main{
  height: 300vh;
}
</style>

<style scoped>
.traceability-system {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background: #fff;
  border-bottom: 1px solid #e4e7ed;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  height: 60px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-left {
  display: flex;
  align-items: center;
}

.company-name {
  font-size: 18px;
  font-weight: bold;
  margin-right: 30px;
  color: #303133;
}

.top-menu {
  border-bottom: none;
}

.top-menu .el-menu-item.active {
  color: #409eff;
  border-bottom: 2px solid #409eff;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.search-input {
  width: 200px;
}

.user-name {
  color: #606266;
  font-weight: 500;
}

.main-container {
  flex: 1;
  height: calc(100vh - 60px);
}

.sidebar {
  background: #f5f7fa;
  border-right: 1px solid #e4e7ed;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.1);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid #e4e7ed;
  background: #fff;
}

.sidebar-title {
  font-size: 16px;
  font-weight: bold;
  color: #303133;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 4px;
  transition: background-color 0.3s;
}

.sidebar-title:hover {
  background: #f0f2f5;
}

.sidebar-menu {
  border-right: none;
  background: transparent;
  padding: 10px 0;
}

.sidebar-menu .el-menu-item {
  margin: 4px 10px;
  border-radius: 6px;
  height: 50px;
  line-height: 50px;
  transition: all 0.3s;
}

.sidebar-menu .el-menu-item:hover {
  background: #e6f7ff;
  color: #409eff;
}

.sidebar-menu .el-menu-item.active {
  background: #409eff;
  color: #fff;
  box-shadow: 0 2px 8px rgba(64, 158, 255, 0.3);
}

.sidebar-menu .el-menu-item .el-icon {
  margin-right: 8px;
  font-size: 18px;
}

.main-content {
  padding: 0;
  background: #f8f9fa;
  overflow: hidden;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .sidebar {
    width: 200px !important;
  }
  
  .header {
    padding: 0 15px;
  }
}

@media (max-width: 768px) {
  .header {
    flex-direction: column;
    height: auto;
    padding: 10px;
  }
  
  .header-left, .header-right {
    width: 100%;
    justify-content: center;
    margin: 5px 0;
  }
  
  .sidebar {
    width: 100% !important;
    height: auto;
  }
  
  .main-container {
    flex-direction: column;
  }
}
</style>